<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <link href="/assets/accessibility.liveRegionAttachment.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="text/babel" data-presets="env,stage-3,react">
      const {
        React: { useEffect },
        ReactDOM: { render },
        WebChat: {
          Components: { BasicWebChat, Composer },
          hooks: { useConnectivityStatus, useSendMessage }
        }
      } = window;

      // TODO: We should use pageObject.sendMessageViaSendBox() instead of useSendMessage() hook.
      run(async function () {
        const SendOnConnect = () => {
          const [connectivityStatus] = useConnectivityStatus();
          const sendMessage = useSendMessage();

          useEffect(() => {
            connectivityStatus === 'connected' && sendMessage('card breakfast');
          }, [connectivityStatus, sendMessage]);

          return false;
        };

        render(
          <Composer
            directLine={WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() })}
            store={testHelpers.createStore()}
            styleOptions={{ internalLiveRegionFadeAfter: 60000 }}
          >
            <BasicWebChat />
            <SendOnConnect />
          </Composer>,
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();
        await pageConditions.minNumActivitiesShown(2);
        await pageConditions.allImagesLoaded();
        await pageConditions.allOutgoingActivitiesSent();
        await pageConditions.scrollToBottomCompleted();
        await pageConditions.liveRegionStabilized();

        await pageObjects.verifyDOMIntegrity();
        await pageObjects.focusSendBoxTextBox();

        await host.sendShiftTab(3);

        await host.snapshot('local');
      });
    </script>
  </body>
</html>
